package logic

import (
	"context"
	"gorm.io/gorm"
	"work-safety/models/mysql"

	"work-safety/workrpc/internal/svc"
	"work-safety/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUpDataLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductUpDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUpDataLogic {
	return &ProductUpDataLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductUpDataLogic) ProductUpData(in *workrpc.ProductUpDataRequest) (*workrpc.ProductUpDataResponse, error) {
	// todo: add your logic here and delete this line
	product := mysql.Product{
		Model:        gorm.Model{ID: uint(in.ProductId)},
		Title:        in.Title,
		Price:        float64(in.Price),
		Address:      in.Address,
		ProductImage: in.ProductImage,
		UserId:       int(in.UserId),
	}
	mysql.DB.Debug().Updates(&product)

	return &workrpc.ProductUpDataResponse{
		ProductId: int64(product.ID),
	}, nil
}
